import 'package:get/get.dart';
import '../store/index.dart';
import 'package:flutter/material.dart';

class ProfileScreen extends StatefulWidget {
  //全局状态控制器
  final globalController = Get.put(GlobalStateController());

  ProfileScreen({Key key}) : super(key: key);

  @override
  _ProfileScreenState createState() => _ProfileScreenState();
}

class _ProfileScreenState extends State<ProfileScreen> {
  List<Map> toUrls = [
    {'title': 'Electron Page', 'url': '/electron'},
    {'title': 'Nested Page', 'url': '/nested'},
    {'title': 'CustomUi Page', 'url': '/nativeUiView'},
    {'title': 'Dialog Page', 'url': '/dialog'},
    {'title': 'Weather Page', 'url': '/weather'},
    {'title': 'Animation Page', 'url': '/animation'},
    {'title': 'Refresh Page', 'url': '/refresh'},
    {'title': 'Location Page', 'url': '/location'},
    {'title': 'Sliver Page', 'url': '/customScroll'},
    {'title': 'WebSite Page', 'url': '/website'},
    {'title': 'OrderInfo Page', 'url': '/orderDetail'},
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("概述"),
      ),
      body: SingleChildScrollView(
        child: Column(children: [
          Container(
            height: 90.0,
            child: Center(
              child: Text('This is a Page'),
            ),
          ),
          Container(
            child: ListView.separated(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              itemCount: 30, // 假设有30个条目
              itemBuilder: (context, index) {
                Map opts = {
                  'url': '/weather',
                  'title': 'Item ${index + 1} Page',
                };
                if (index < toUrls.length) {
                  final Map target = toUrls[index];
                  opts = {'title': target['title'], 'url': target['url']};
                }
                return ListTile(
                  title: Text(opts['title']),
                  onTap: () {
                    Get.toNamed(opts['url']);
                  },
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return Divider(
                  color: Colors.grey,
                  height: 2.0,
                );
              },
            ),
          )
        ]),
      ),
      endDrawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            UserAccountsDrawerHeader(
              accountName: Text('Your Name'),
              accountEmail: Text('your.email@example.com'),
              currentAccountPicture: CircleAvatar(
                backgroundImage: NetworkImage(
                    'https://profile-avatar.csdnimg.cn/default.jpg'),
              ),
            ),
            ListTile(
              leading: Icon(Icons.home),
              title: Text('Home'),
              onTap: () {
                // Update the state of the app
                widget.globalController.changeBottomBarIndex(0);
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              leading: Icon(Icons.settings),
              title: Text('Settings'),
              onTap: () {
                // Update the state of the app
                widget.globalController.changeBottomBarIndex(3);
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}
